<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>获取地理位置</title>
</head>

<body>
    <script>
        console.log(window.navigator.userAgent);

        let position = window.navigator.geolocation.getCurrentPosition(res => {
            // 获取成功执行
            console.log("获取成功", res.coords);
            console.log(res.coords.longitude, res.coords.latitude,"Location in Canada");
        }, ex => {
            console.log("获取失败", ex);
        });
    </script>
</body>

</html>